﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using BHair.Base;

namespace BHair
{
    public partial class Frmuser : WeifenLuo.WinFormsUI.Docking.DockContent
    {
        public Frmuser()
        {
            InitializeComponent();
        }
        string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
        private void Frmuser_Load(object sender, EventArgs e)
        {
            selectuser();
           //this.dataGridView1.CurrentRow.Selected = true;
        }
        public void selectuser() 
        {
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            string sql = "SELECT [LoginUserID] as 账号,[username] as 用户名 FROM [LoginUser]";
            DataTable dt = new DataTable();
            SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
            sda.Fill(dt);
            this.dataGridView1.DataSource = dt;
            conn.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            /*
             * 判断权限是否勾选如果勾选则赋值为1 否为0
             * */
            int xfgl = 0;
            int hygl=0;
            int yggl = 0;
            //int hyxf = 0;
            int jcxf = 0;
            int hycz = 0;
            int spsz = 0;
            int hylx = 0;
            int xtsz = 0;
            int hycztj = 0;
            int zmqd = 0;
            int yggztj = 0;
            int mysztj = 0;
            int sjhf = 0;
            int sjbf = 0;
            int sjsj = 0;
            int yhsz = 0;
            int szkmgl = 0;
            int sprk = 0;
            int jcxfmx = 0;
            int zjkk = 0;
            int xsmx = 0;
            int jhmx = 0;
            int kcbb = 0;
            int kcpd = 0;
            int kaiban = 0;
            int spfl = 0;
            int jcxm = 0;
            if (cbjcxm.Checked)
            {
                jcxm = 1;
            }
            if (cbspfl.Checked)
            {
                spfl = 1;
            }
            if (cbkcpd.Checked)
            {
                kcpd = 1;
            }
            if (cbkcbb.Checked)
            {
                kcbb = 1;
            }
            if (cbjhmx.Checked)
            {
                jhmx = 1;
            }
            if (cbxsmx.Checked)
            {
                xsmx = 1;
            }
            if (cbxfgl.Checked)     
            {
                xfgl = 1;
            }
             if (xbhygl.Checked) 
            {
                hygl = 1;
            }
             if (xbyggl.Checked) 
            {
                yggl = 1;
            }
             if (xbjcxf.Checked) 
            {
                jcxf = 1;
            }
            if (xbhycz.Checked) 
            {
                hycz = 1;
            }
             if (cbspsz.Checked) 
            {
                spsz = 1;
            }
             if (cbhylx.Checked) 
            {
                hylx = 1;
            }
             if (cbxtsz.Checked) 
            {
                xtsz = 1;
            }
             if (cbhycztj.Checked) 
            {
                hycztj = 1;
            }
             if (cbzmqd.Checked) 
            {
                zmqd = 1;
            }
            if (cbyggztj.Checked) 
            {
                yggztj = 1;
            }
            if (cbmysztj.Checked) 
            {
                mysztj = 1;
            }
             if (cbsjhf.Checked) 
            {
                sjhf = 1;
            }
             if (cbsjbf.Checked) 
            {
                sjbf = 1;
            }
             if (cbxtsj.Checked) 
            {
                sjsj = 1;
            }
             if (cbyhsz.Checked) 
            {
                yhsz = 1;
            }
             if (cbszkmgl.Checked) 
            {
                szkmgl = 1;
            }
             if (cbsprk.Checked) 
            {
                sprk = 1;
            }
             if (cbjcxfmx.Checked) 
            {
                jcxfmx = 1;
            }
            if(cbzjkk.Checked)
            {
                zjkk = 1;
            }
            if (cbkaiban.Checked)
            {
                kaiban = 1;
            }
            string userid = this.dataGridView1.SelectedCells[0].Value.ToString();
            string sql =string.Format( "UPDATE [LoginUser]"
                + "  SET    [xiaofei] ={0}"
                + "      ,[huiyuanguanli] ={1}"
                + "      ,[spsz] = {2}"
                + "      ,[ygsz] = {3}"
                + "      ,[jcxf] = {4}"
                + "      ,[xtsz] = {5}"
                + "      ,[yhsz] = {6}"
                +"      ,[sjsj] = {7}"
                + "      ,[hycztj] ={8}"
                + "      ,[yggztj] ={9}"
                + "      ,[myszhz] ={10}"
                + "      ,[jcxfmx] ={11}"
                + "      ,[hycz] = {12}"
                + "      ,[hylx] = {13}"
                + "      ,[zmqd] = {14}"
                + "      ,[sjbf] = {15}"
                + "      ,[sjhf] = {16}"
                + "      ,[szkmgl] = {17}"
                + "      ,[sprk] ={18}"
                + "      ,[zjkk] ={19}"
                +"       ,[xsmx] ={20} "
                +"       ,[jhmx]= {21} "
                +"       ,[kcbb]={22}"
                +"       ,[kcpd]={23},[kaiban]={24},[spfl]={25},jcxmgl={26}"
                + " WHERE LoginUserID='{27}'",xfgl,hygl,spsz,yggl,jcxf,xtsz,yhsz,sjsj,hycztj,yggztj,mysztj,jcxfmx,hycz,hylx,zmqd,sjbf,sjhf,szkmgl,sprk,zjkk, xsmx,jhmx,kcbb,kcpd,kaiban ,spfl,jcxm,userid);
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            SqlCommand comm = new SqlCommand(sql,conn);
            comm.ExecuteNonQuery();
            MessageBox.Show("设置成功");
            conn.Close();
        }

        

        
        public void looad() 
        {
            cbxfgl.Checked = false;
        }

       
        

        private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            
            
        }

        private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
        {
            //InitializeComponent();
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            button2.Visible = true; 
            int xfgl = 0;
            int hygl = 0;
            int yggl = 0;
            //int hyxf = 0;
            int jcxf = 0;
            int hycz = 0;
            int spsz = 0;
            int hylx = 0;
            int xtsz = 0;
            int hycztj = 0;
            int zmqd = 0;
            int yggztj = 0;
            int mysztj = 0;
            int sjhf = 0;
            int sjbf = 0;
            int sjsj = 0;
            int yhsz = 0;
            int szkmgl = 0;
            int sprk = 0;
            int jcxfmx = 0;
            int zjkk = 0;
            int xsmx = 0;
            int jhmx = 0;
            int kcbb = 0;
            int kcpd = 0;
            int kaiban = 0;
            int spfl = 0;
            int jcxm = 0;
            string userid = this.dataGridView1.SelectedCells[0].Value.ToString();
            //MessageBox.Show(userid);
            string sql = string.Format("SELECT [xiaofei]"
                + "      ,[huiyuanguanli]"
                + "      ,[spsz]"
                + "      ,[ygsz]"
                + "      ,[jcxf]"
                + "      ,[xtsz]"
                + "      ,[yhsz]"
                + "      ,[sjsj]"
                + "      ,[hycztj]"
                + "      ,[yggztj]"
                + "      ,[myszhz]"
                + "      ,[jcxfmx]"
                + "      ,[hycz]"
                + "      ,[hylx]"
                + "      ,[zmqd]"
                + "      ,[sjbf]"
                + "      ,[sjhf]"
                + "      ,[szkmgl]"
                + "      ,[sprk]"
                +"       ,[zjkk]"
                +"       ,[xsmx]"
                +"       ,[jhmx]"
                +"       ,[kcbb]"
                +"       ,[kcpd],[kaiban],[spfl],jcxmgl"
                + "  FROM [LoginUser] where LoginUserID='{0}' ",userid);
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            SqlCommand comm = new SqlCommand(sql, conn);
            SqlDataReader sdr = comm.ExecuteReader();
            while (sdr.Read())
            {
                xfgl = Int32.Parse(sdr["xiaofei"].ToString().Trim());
                hygl = Int32.Parse(sdr["huiyuanguanli"].ToString().Trim());
                yggl = Int32.Parse(sdr["ygsz"].ToString().Trim());
                jcxf = Int32.Parse(sdr["jcxf"].ToString().Trim());
                hycz = Int32.Parse(sdr["hycz"].ToString().Trim());
                spsz = Int32.Parse(sdr["spsz"].ToString().Trim());
                hylx = Int32.Parse(sdr["hylx"].ToString().Trim());
                xtsz = Int32.Parse(sdr["xtsz"].ToString().Trim());
                hycztj = Int32.Parse(sdr["hycztj"].ToString().Trim());
                zmqd = Int32.Parse(sdr["zmqd"].ToString().Trim());
                yggztj = Int32.Parse(sdr["yggztj"].ToString().Trim());
                mysztj = Int32.Parse(sdr["myszhz"].ToString().Trim());
                sjhf = Int32.Parse(sdr["sjhf"].ToString().Trim());
                sjbf = Int32.Parse(sdr["sjbf"].ToString().Trim());
                sjsj = Int32.Parse(sdr["sjsj"].ToString().Trim());
                yhsz = Int32.Parse(sdr["yhsz"].ToString().Trim());
                szkmgl = Int32.Parse(sdr["szkmgl"].ToString().Trim());
                sprk = Int32.Parse(sdr["sprk"].ToString().Trim());
                jcxfmx = Int32.Parse(sdr["jcxfmx"].ToString().Trim());
                zjkk = Int32.Parse(sdr["zjkk"].ToString().Trim());
                xsmx= Int32.Parse(sdr["xsmx"].ToString().Trim());
                jhmx= Int32.Parse(sdr["jhmx"].ToString().Trim());
                kcbb= Int32.Parse(sdr["kcbb"].ToString().Trim());
                kcpd= Int32.Parse(sdr["kcpd"].ToString().Trim());
                kaiban= Int32.Parse(sdr["kaiban"].ToString().Trim());
                spfl= Int32.Parse(sdr["spfl"].ToString().Trim());
                jcxm= Int32.Parse(sdr["jcxmgl"].ToString().Trim());
            }
            if (jcxm == 1)
            {
                cbjcxm.Checked = true;
            }
            if (spfl == 1)
            {
                cbspfl.Checked = true;
            }
            else
            {
                cbspfl.Checked = false;
            }
            if (kaiban == 1)
            {
                cbkaiban.Checked = true;
            }
            else
            {
                cbkaiban.Checked = false;
            }
            if (kcpd == 1)
            {
                cbkcpd.Checked = true;
            }
            else
            {
                cbkcpd.Checked = false;
            }
            if (kcbb == 1)
            {
                cbkcbb.Checked = true;
            }
            else
            {
                cbkcbb.Checked = false;
            }
            if (jhmx == 1)
            {
                cbjhmx.Checked = true;
            }
            else
            {
                cbjhmx.Checked = false;
            }
            if (xsmx == 1)
            {
                cbxsmx.Checked = true;
            }
            else
            {
                cbxsmx.Checked = false;
            }
            if (xfgl == 1)
            {
                cbxfgl.Checked = true;
            }
            else
            {
                cbxfgl.Checked = false;
            }
            if (hygl == 1)
            {
                xbhygl.Checked = true;
            }
            else 
            {
                xbhygl.Checked = false;
            }
            if (yggl == 1)
            {
                xbyggl.Checked = true;
            }
            else 
            {
                xbyggl.Checked = false;
            }
            if (jcxf == 1)
            {
                xbjcxf.Checked = true;
            }
            else 
            {
                xbjcxf.Checked = false;
            }
            if (hycz == 1)
            {
                xbhycz.Checked = true;
            }
            else 
            {
                xbhycz.Checked = false;
            }
            if (spsz == 1)
            {
                cbspsz.Checked = true;
            }
            else 
            {
                cbspsz.Checked = false;
            }
            if (hylx == 1)
            {
                cbhylx.Checked = true;
            }
            else 
            {
                cbhylx.Checked = false;
            }
            if (xtsz == 1)
            {
                cbxtsz.Checked = true;
            }
            else 
            {
                cbxtsz.Checked = false;
            }
            if (hycztj == 1)
            {
                cbhycztj.Checked = true;
            }
            else 
            {
                cbhycztj.Checked = false;
            }
            if (zmqd == 1)
            {
                cbzmqd.Checked = true;
            }
            else 
            {
                cbzmqd.Checked = false;
            }
            if (yggztj == 1)
            {
                cbyggztj.Checked = true;
            }
            else 
            {
                cbyggztj.Checked = false;
            }
            if (mysztj == 1)
            {
                cbmysztj.Checked = true;
            }
            else 
            {
                cbmysztj.Checked = false;
            }
            if (sjhf == 1)
            {
                cbsjhf.Checked = true;
            }
            else 
            {
                cbsjhf.Checked = false;
            }
            if (sjbf == 1)
            {
                cbsjbf.Checked = true;
            }
            else 
            {
                cbsjbf.Checked = false;
            }
            if (sjsj == 1)
            {
                cbxtsj.Checked = true;
            }
            else 
            {
                cbxtsj.Checked = false;
            }
            if (yhsz == 1)
            {
                cbyhsz.Checked = true;
            }
            else 
            {
                cbyhsz.Checked = false;
            }
            if (szkmgl == 1)
            {
                cbszkmgl.Checked = true;
            }
            else 
            {
                cbszkmgl.Checked = false;
            }
            if (sprk == 1)
            {
                cbsprk.Checked = true;
            }
            else 
            {
                cbsprk.Checked = false;
            }
            if (jcxfmx == 1)
            {
                cbjcxfmx.Checked = true;
            }
            else 
            {
                cbjcxfmx.Checked = false;

            }
            if (zjkk == 1)
            {
                cbzjkk.Checked = true;
            }
            else 
            {
                cbzjkk.Checked = false;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            frmaddyh yh = new frmaddyh();
            yh.ShowDialog();
            selectuser();

        }
    }
}
